
$(function(){
    $("#UpMaterial").dialog({
        title:"修改",
        btnName:"修改",
        btnBind:function(){
            var params=$("#updateMaterial").serializeArray();
            var param="";
            for(var i in params){

                if(i==params.length-1){
                    param+=params[i].name+"="+params[i].value;
                }else{
                    param+=params[i].name+"="+params[i].value+"&";
                }
            }
            console.info(param)


            $.post("base/whCgMapping/updateWhCgMapping",param,function (msg) {
                $("#UpMaterial").dialog("close");
                $("#table").bootstrapTable("refresh");
                toastr.warning("信息提示",msg);
            },"text")
        }
    });

    $("#AddMaterial").dialog({
        title:"添加",
        btnName:"添加",
        btnBind:function(){
            var params=$("#table1").bootstrapTable("getSelections");
            console.info(params);
            var param="";
           $(params[0]).each(function () {
               console.info(this)
               for(var i in this){
                   param+=i+"="+this[i]+"&";
               }
           })
            param=param.substring(0,param.length-1);
            console.info(param)


            $.post("base/whCgMapping/addWhCgMapping",param,function (msg) {
                $("#AddMaterial").dialog("close");
                $("#table").bootstrapTable("refresh");
                toastr.warning("信息提示",msg);
            },"text")
        }
    });
});



/**
 * 导出
 * @param fmt
 */
function exportFile(fmt){
    location='base/whCgMapping/report?format='+fmt;
}


function FormatOperation(value,row,index){
    var peration = "<span class='btn btn-default' onclick='updateMaterial("+JSON.stringify(row)+")'><i class='glyphicon glyphicon-edit'></i>详情</span>&nbsp;<span class='btn btn-warning' onclick='deleteMaterial("+row.whCgMappingId+")'><i class='glyphicon glyphicon-remove'></i>删除</span>";
    return peration;
}

function addMaterial() {
    $(".modal .modal-body #AddMaterial").attr("class","show");
    $("#AddMaterial").dialog("open");
}

function searchTjDictionary() {
    var param=$("#condition1").serializeArray();
    console.info(param)

    var obj={};
    for(var i in param){
        obj[param[i].name]=param[i].value;
    }
    $("#table1").bootstrapTable("refresh",{query:obj});

}


function  updateMaterial(row) {
    $("#updateMaterial").setForm(row);



    $(".modal .modal-body #UpMaterial").attr("class","show");
    $("#UpMaterial").dialog("open");
    console.info(row);
}

function deleteMaterial(aid) {
    var param="id="+aid;
    $.post("base/whCgMapping/delWhCgMapping",param,function (msg) {
        toastr.warning(msg);
        $("#table").bootstrapTable("refresh")
    },"text")
}
function searchTjMaterial() {
    var param = $("#condition").serializeArray();
    console.info(param)

    var obj = {};
    for (var i in param) {
        obj[param[i].name] = param[i].value;
    }
    $("#table").bootstrapTable("refresh", {query: obj});

}